import {
	reqCategoryPageData
} from '../../api/category'

Page({
	data: {
		activeFirstLevelId: '',
		categoryList: [],
		secondLevelList: [],
		loading: true
	},
	onLoad() {
		this.initData()
	},
	async initData() {
		const res = await reqCategoryPageData()
		const result = res.data
		this.setData({
			activeFirstLevelId: result[0].id,
			categoryList: result,
			secondLevelList: result[0].children,
			loading: false
		})
	},
	handlerBindTap(event) {
		const findItem = this.data.categoryList.find(item => item.id === event.target.dataset.id)
		this.setData({
			activeFirstLevelId: event.target.dataset.id,
			secondLevelList: findItem ? findItem.children : []
		})
	}

})